package 
{
	import net.flashpunk.Entity;
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Text;
	import net.flashpunk.utils.Data;
	
	/**
	 * ...
	 * @author ...Felix Fleiß
	 */
	public class Score extends Entity
	{
		private var time:Number;
		private var score:Number;
		private var text:Text;
		private var started:Boolean;
		public function Score() {
			score = 0;
			time = Data.readInt("time_to_play");
			addGraphic(new Text(getScoreString(), 100, 100));
			text = new Text(getScoreString(),  Data.readInt("screen_width") / 2-90, 0,200);
			addGraphic(text);
			started = false;
		}
		override public function update():void 
		{
			super.update();
			if(started){
				time -= FP.elapsed;
				if (time < 0)
					time = 0;
			}
			text.text = getScoreString();
		}
		private function  getScoreString():String {
			return String("Time: " + int(time) + "\tScore: " + int(score));
		}
		public function addScore(val:Number):void {
			if (time != 0)
				score += val;
		}
		public function addTime(val:Number):void {
			if (time != 0)
				time += val;
		}
		public function isGameOver():Boolean {
			if (time == 0)
				return true;
			else
				return false;
		}
		public function startGame():void {
			started = true;
		}
		public function getScore():Number {
			return score;
		}
		public function getTime():Number {
			return time;
		}
	}
	
}